package com.jn.erp.web.api.course.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jn.erp.utils.DateUtils;
import com.jn.erp.utils.RedisLock;
import com.jn.erp.web.api.course.entity.TCourseOrder;
import com.jn.erp.web.api.course.entity.TCourseOrderConfig;
import com.jn.erp.web.api.course.mapper.TCourseOrderConfigMapper;
import com.jn.erp.web.api.course.service.TCourseOrderService;
import com.jn.erp.web.api.student.entity.TStudentClassRela;
import com.jn.erp.web.api.student.mapper.TStudentClassRelaMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 周期性创建课程记录-每月执行一次，创建近90天的课程记录，在排课配置新建时初始化
 * */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class TCourseOrderTaskImplement {
    @Autowired
    private TCourseOrderTask tCourseOrderTask;
    @Autowired
    private RedisLock redisLock;
    //每天21:00运行
    @Scheduled(cron = "0 0 21 * * ?")
    public void createCourseOrder() {
        log.info("----------------------------  createCourseOrder   start --------------------------------------");
        Boolean idxScoreReportsTask = redisLock.lock("TCourseOrderTaskImplement:createCourseOrder");
        if (!idxScoreReportsTask) {
            return;
        }
        tCourseOrderTask.createCourseOrder();

        try {

            log.info("---------------------------- Create createCourseOrder   end --------------------------------------");
        } catch (Exception e) {
            System.out.println("TCourseOrderTask=====>>>>>" + e.getMessage());
            log.info(e.getMessage());
            e.printStackTrace();
        } finally {
            redisLock.del("TCourseOrderTaskImplement:createCourseOrder");
        }

    }
}
